<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>诉讼申请(小额贷账单)</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="sqPanel" style="margin-bottom: 5px;">
        <div class="sqPanel_head" style="height:35px;">
            <table class="table_full">
                <tr>
                    <td><span >---诉讼申请单---</span></td>
                </tr>
            </table>
        </div>
    </div>
    <form id="addAcc_form">
        <input name="lawyerId" id="lawyerId" type="hidden" class="ui-textbox" value=""  >
        <input name="lawyerNm" id="lawyerNm" type="hidden" class="ui-textbox" value="" >

        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_33">
                <div class="label">申请人</div>
                <div class="field">
                    <input name="applyerNm" id="applyerNm" disabled="disabled" type="text" data-type="text" class="ui-textbox" value="${usrNm}" validate="{required:true}">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">申请人电话</div>
                <div class="field">
                    <input name="applyerPhone" id="applyerPhone" type="text" class="ui-textbox" value="" >
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">申请时间</div>
                <div class="field">
                    <input name="applyerDt" id="applyerDt"  disabled="disabled" type="text" class="ui-datepicker" value="${now}">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">违约类型</div>
                <div class="field">

                    <select name="breachTypCd" id="breachTypCd" data-value=" " validate="{required:true,select:true}">
                        <option value=" ">请选择</option>
                        <c:forEach items="${breachTypList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">诉讼方式</div>
                <div class="field">

                    <select name="sueWayCd" id="sueWayCd" data-value=" " validate="{required:true,select:true}">
                        <option value=" ">请选择</option>
                        <c:forEach items="${sueWayList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否有可执行资产</div>
                <div class="field">

                    <select name="isHaveAssCd" id="isHaveAssCd" data-value=" " validate="{required:true,select:true}">
                        <option value=" ">请选择</option>
                        <c:forEach items="${yesNoList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否保全</div>
                <div class="field">

                    <select name="isWell" id="isWell" data-value=" " validate="{required:true,select:true}">
                        <option value=" ">请选择</option>
                        <c:forEach items="${yesNoList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">保全费</div>
                <div class="field">
                    <input name="wellAmt" id="wellAmt" type="text" class="ui-textbox" value=""  >
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">诉讼管辖</div>
                <div class="field">
                    <select name="sueDomainCd" id="sueDomainCd" data-value=" ">
                        <option value=" ">请选择</option>
                        <c:forEach items="${sueDomainList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="lawyerBox1"  >
                <div class="label">受理法务</div>
                <div class="field">
                    <select name="lawyer1" id="lawyer1" data-value=" " >
                        <option value=" ">请选择</option>
                        <c:forEach items="${usrList1 }" var="bk">
                            <option value="${bk.id }">${bk.refRlNm }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="lawyerBox2"  >
                <div class="label">受理法务</div>
                <div class="field">
                    <select name="lawyer2" id="lawyer2" data-value=" " >
                        <option value=" ">请选择</option>
                        <c:forEach items="${usrList2 }" var="bk">
                            <option value="${bk.id }">${bk.refRlNm }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">诉讼申请说明</div>
                <div class="field">
                    <textarea name="lawyerRem" id="lawyerRem" rows="3" class="l-textarea" style="width:98%" value="" ></textarea>
                </div>
            </div>


            <div class="fieldBox col_100" id="uploadBox">
                <div class="label">资料上传</div>
                <div class="field">
                    <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                        <jsp:param name="filePath" value="sue"/>
                    </jsp:include>
                </div>
            </div>
            <div class="fieldBox col_100" id="fileModify">
                <div class="label">资料</div>
                <div class="field">
                    <jsp:include page="../../system/sysUlFilesRec/sysUlFileRecListDetail.jsp" flush="true" >
                        <jsp:param name="pkId" value="${applyId }"/>
                        <jsp:param name="tabNm" value=""/>
                    </jsp:include>
                </div>
            </div>
        </div>

        <div class="sqPanel" style="margin-bottom: 5px;">
            <div class="sqPanel_head" style="height:35px;">
                <table class="table_full">
                    <tr>
                        <td><span >---小贷贷账单信息---</span></td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="mcrGrid" class="sq-grid" style="height:200px"></div>

        <div class="btnsBox">
            <span id="saveNewAcc_Btn" class="sq-button sq-button-hasicon l-dialog-btn-ok"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
</div>
<script type="text/javascript">
    var lawyerNeedFlag = '${lawyerNeedFlag}';
    var applyId = '${applyId}';
    var dataId = '${dataId}';
    var viewFlag = '${viewFlag}';
    var taskFlag = '${taskFlag}';
    var rmSvBtn = '${rmSvBtn}';
    $(function () {
        $("#addAcc_form").ligerForm({validate:true});
        liger.get("applyerDt").setDisabled();
        $("#lawyerBox1").hide();
        $("#lawyerBox2").hide();

        if(StringUtils.isNotEmpty(applyId)){
            initEdit();
        }
        if(StringUtils.isNotEmpty(viewFlag)){
            initView();
        }
        if ('1' == rmSvBtn) {
            $("#saveNewAcc_Btn").hide();
        }
    });
    /**
     * 仅查看
     * */
    function initView(){
        $("#saveNewAcc_Btn").hide();
        $("#sueDomainCd").ligerGetComboBoxManager().setDisabled();
        $("#lawyer1").ligerGetComboBoxManager().setDisabled();
        $("#lawyer2").ligerGetComboBoxManager().setDisabled();
    }
    /**
     * 合同链接
     * @param dataId
     */
    function cntLnk(dataId){
        if(StringUtils.isNotEmpty(dataId)){
            Add_navTab('cstDetail'+dataId,'小贷合同',"<%=path%>/mcr/mcrBillM/toBillDtlPage.do?id=" + dataId);
        }else{
            $.ligerDialog.error('error')
        }
    }
    /**
     * 初始化编辑页面的值
     */
    function initEdit(){
        $("#applyerNm").val('${dto.applyerNm}');
        $("#applyerPhone").val('${dto.applyerPhone}');
        $("#applyerDt").val('${dto.applyerDt}');
        $("#breachTypCd").ligerGetComboBoxManager().setValue('${dto.breachTypCd}')
        $("#sueWayCd").ligerGetComboBoxManager().setValue('${dto.sueWayCd}')
        $("#isHaveAssCd").ligerGetComboBoxManager().setValue('${dto.isHaveAssCd}')
        $("#isWell").ligerGetComboBoxManager().setValue('${dto.isWell}')
        $("#wellAmt").val('${dto.wellAmt}');
        var sudDomainCd = '${dto.sueDomainCd}';
        $("#sueDomainCd").ligerGetComboBoxManager().setValue(sudDomainCd);
        if(StringUtils.isNotEmpty(sudDomainCd) && sudDomainCd =="0001"){
            $("#lawyerBox1").show();
            $("#lawyer1").ligerGetComboBoxManager().setValue('${dto.lawyerId}');
        }else{
            $("#lawyerBox2").show();
            $("#lawyer2").ligerGetComboBoxManager().setValue('${dto.lawyerId}');
        }
        $("#lawyerRem").val('${dto.lawyerRem}');
        initEditAble();

    }

    /**
     *  设置编辑页面不能编辑的东西
     */
    function initEditAble(){
        liger.get("applyerPhone").setDisabled();
        $("#breachTypCd").ligerGetComboBoxManager().setDisabled();
        $("#sueWayCd").ligerGetComboBoxManager().setDisabled();
        $("#isHaveAssCd").ligerGetComboBoxManager().setDisabled();
        $("#isWell").ligerGetComboBoxManager().setDisabled()
        liger.get("wellAmt").setDisabled();
        $("#lawyerRem").attr("disabled",true);
        $("#uploadBox").hide();
    }
    $("#saveNewAcc_Btn").click(function(){
        if(validWellAmt){
            var wellAmt = $("#wellAmt").val();
            if(StringUtils.isEmpty(wellAmt)){
                $.ligerDialog.error('请填写保全费！');
                return false;
            }
        }
        var lawyerId = $("#lawyerId").val();
        var sueDomainCd = $("#sueDomainCd").val();
        if ('2' == taskFlag) {
            // 贷后管理中心审批
            if (StringUtils.isEmpty(sueDomainCd)) {
                $.ligerDialog.error('请选择诉讼管辖！');
                return false;
            } else if ('0002' == sueDomainCd) {
                // 属地
                if (StringUtils.isEmpty(lawyerId)) {
                    $.ligerDialog.error('请选择受理法务！');
                    return false;
                }
            }
        } else if ('4' == taskFlag) {
            // 风险管理部审批
            if (StringUtils.isEmpty(sueDomainCd)) {
                $.ligerDialog.error('请选择诉讼管辖！');
                return false;
            } else {
                if (StringUtils.isEmpty(lawyerId)) {
                    $.ligerDialog.error('请选择受理法务！');
                    return false;
                }
            }
        }
        var waiting = $.ligerDialog.waitting('正在保存中,请稍候...');
        var ligerForm = liger.get("addAcc_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            waiting.close();
            return false; //验证不通过，不执行以下代码
        }
        var uploadParam = JSON.stringify(getUploadResultParams());
        var data = ligerForm.getData();
        data['uploadParam'] = uploadParam;
        data['dataId'] = dataId;
        data['dataTable'] = dataTable;
        if(StringUtils.isNotEmpty(lawyerNeedFlag) ){
            if(StringUtils.isEmpty(lawyerId) ){
                $.ligerDialog.error('请选择受理律师！');
                return false;
            }
        }
        data['lawyerId'] = lawyerId;
        data['lawyerNm'] = $("#lawyerNm").val();
        if(applyId){
            data['id'] = applyId;
        }
        var url = '<%=path%>/sue/sueApplyInfo/saveOrUpdate.do';

        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            success:function(data){
                waiting.close();
                var success = data.success;
                if(success == "1"){
                    $.ligerDialog.success('保存完毕',"提示",function(){
                        if (StringUtils.isEmpty(taskFlag)) {
                            var callback = GET_W2Wcallback();
                            callback();
                            Remove_navTab();
                        }
                    })
                }else if(success == "1"){
                    $.ligerDialog.success('保存完毕');
                }else{
                    $.ligerDialog.error(data.info)
                }
            }
        });
    })
    var validWellAmt = false;
    $("#isWell").change(function(){
        var val = $(this).val();
        if(StringUtils.isNotEmpty(val) && val=="1"){
            validWellAmt = true;
            $("#wellAmtSpan").show();
        }else{
            validWellAmt =false;
            $("#wellAmtSpan").hide();
        }
    });
    $("#sueDomainCd").change(function(){
        var val = $(this).val();
        if(StringUtils.isNotEmpty(val) && val == "0001"){
            $("#lawyer1").val("");
            $("#lawyerBox1").show();
            $("#lawyerBox2").hide();
        }else{
            $("#lawyer2").val("");
            $("#lawyerBox2").show();
            $("#lawyerBox1").hide();
        }
        $("#lawyerId").val();
        $("#lawyerNm").val();

    });

    $("#lawyer1").change(lawyerChange);
    $("#lawyer2").change(lawyerChange)
    function lawyerChange(){
        var val = $(this).val();
        var text = $(this).find("option:selected").text();
        if(StringUtils.isNotEmpty(val)){
            $("#lawyerId").val(val);
            $("#lawyerNm").val(text);
        }else{
            $("#lawyerId").val("");
            $("#lawyerNm").val("");
        }
    }
</script>
<script>
    var dataTable="MCR_BILL_M"
    var mcrGrid = null;
    $(function () {
        initMcrGrid();
    })
    function initMcrGrid(){
        var url = '<%=path%>/sue/sueApplyInfo/initMcrList.do';
        mcrGrid = $("#mcrGrid").ligerGrid({
            url:url,
            parms:{mcrId:'${dataId}'},
            method: 'get',
            columns: [
                {display: '贷款合同号', name: 'paySchNo', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if(value&&value!="null"){
                            h+='<a href="javascript:cntLnk(';
                            h+="'"+rowdata.paySchId+"'";
                            h+=')">'+value+'</a>'
                        }
                        return h;
                    },
                },
                {display: '贷款类型', name: 'crTypCdNm', width: 150, align: 'right', enabledSort: false},
                {display: '业务类型', name: 'bizTypCdNm', width: 150, align: 'right', enabledSort: false},
                {
                    display: '实际贷款金额(元)', name: '', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.crAmt/100);
                    }
                },
                {
                    display: '已还本金合计(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.paidCapAmt / 100);
                    }
                },
                {
                    display: '已还利息合计(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.paidIntrAmt / 100);
                    }
                },
                {
                    display: '已还罚息合计(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.paidPntAmt / 100);
                    }
                },
                {
                    display: '剩余本金合计(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.leftCapAmt / 100);
                    }
                },
                {
                    display: '剩余利息合计(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.leftIntrAmt / 100);
                    }
                },
                {
                    display: '剩余罚息合计(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.leftPntAmt / 100);
                    }
                },
                {
                    display: '逾期租金合计(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.overdueRentAmt / 100);
                    }
                },
                {
                    display: '经营贷应收结清款(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.operLoanAmt / 100);
                    }
                }


            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '200',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            rownumbers: false,  //显示序号
            onBeforeShowData: function () {
                var grid = this;
                grid.collapsedRows = [];
            }
        })
    }
</script>
</body>
</html>
